import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login.vue'

Vue.use(VueRouter)

const routes = [

  {
    path:"/",
    redirect:"/login"
  },
  {
    path:"/login",
    name:"Login",
    component: Login
  },
  {
    path:"/index",
    name:"Index",
    component: ()=> import ("@/views/Index.vue"),
    children:[
      {
        path: "/index/JingXuanContext",
        name: "jingxuancontext",
        component: ()=>import("@/components/JingXuanContext")
      },
      {
        path: "/index/CourseEvaluation",
        name: "CourseEvaluation",
        component:()=>import("@/components/CourseEvaluation")
      },
      {
        path:"/notice",
        name: "notice",
        component: ()=> import("@/components/NoticeComponent")
      },
      {
        path: "/index/WelfareContentView",
        name: "WelfareContentView",
        component:()=>import("@/components/WelfareContentView")
      },

   
      {
        path: "/index/consultReply",
        name: "consultReply",
        component:()=>import("@/components/ConsultReply")
      },
      {
        path: "/index/consultproblem",
        name: "consultproblem",
        component: ()=>import("@/components/ConsultProblem")
       },
      {
        path:"/heartmark",
        name: "heartmark",
        component:()=> import("@/components/HeartmarkComponent")
      },
      {
        path: "/index/HeartKnowledge",
        name: "HeartKnowledge",
        component: () => import("@/components/HeartKnowledge")
    },
      {
        path:"/kecheng",
        name: "kecheng",
        component: ()=> import("@/components/KeChengGuanLi")
      },
      {
        path: "/index/FM",
        name: "FM",
        component: ()=>import("@/components/FM.vue")
      }

    ]
  },
  {
    path: "/indexAdmin",
    name: "IndexAdmin",
    component: ()=> import("@/views/indexAdmin"),
    children:[
      {
        path: "/indexAdmin/userAdmin",
        name: "userAdmin",
        component:()=>import("@/components/UserAdmin")
      }
    ]
  },
  {
    path: "/newTest",
    name: "newTest",
    component: ()=>import("@/components/newTest")
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//路由守卫
router.beforeEach((to,from,next)=>{

  //不需要登录就能访问的页面
  if(to.name == 'Login'){
    next()
    return;
  }


  //需要登录才能访问的页面
  const   uid=sessionStorage.getItem("uid")
  if(uid==null||uid==undefined){
    next("/login")
    return;
  }
  next()

})

export default router